//
//  MyCollectionViewController.m
//  心水宝典
//
//  Created by zr on 2018/8/29.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyCollectionViewController.h"
#import "MyCollectionHeaderView.h"
#import "MyCollectionTableViewCell.h"

@interface MyCollectionViewController ()

@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIView * oneLineView;
@property (nonatomic, strong)UIView * twoLineView;
@property (nonatomic, weak)UIImageView * contentImageView;
//@property (nonatomic, weak)UITableView * tableView;

@end

@implementation MyCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = WHITE_COLOR;
    
    [self setupNav];
    [self setupUI];
}

- (void)setupNav{
    
    self.title = @"我的收藏";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    //    backButton.frame = CGRectMake(0, 0, 20 * SCREENH6, 20 * SCREENH6);
    backButton.size = CGSizeMake(20 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
    
}


- (void)setupUI{
    
//    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT) style:UITableViewStylePlain];
//    tableView.delegate = self;
//    tableView.dataSource = self;
//    tableView.backgroundColor = [UIColor whiteColor];
//    tableView.rowHeight = 115 * SCREENH6;
//    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//
//    self.tableView = tableView;
//
//    [self.tableView registerClass:[MyCollectionTableViewCell class] forCellReuseIdentifier:@"MycollectionListCell"];
//    [self.tableView registerClass:[MyCollectionHeaderView class] forHeaderFooterViewReuseIdentifier:@"MyCollectionHeaderView"];
//
//    [self.view addSubview:self.tableView];
    
    self.oneButton = [self setupButtonWith:@"趣味测算"];
    self.oneButton.selected = YES;
    
    [self.view addSubview:self.oneButton];
    
    self.twoButton = [self setupButtonWith:@"命理专栏"];
    [self.view addSubview:self.twoButton];
    
    self.oneLineView = [self setupLineView];
    self.oneLineView.hidden = NO;
    
    [self.view addSubview:self.oneLineView];
    
    self.twoLineView = [self setupLineView];
    [self.view addSubview:self.twoLineView];
    
    UIImageView * contentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(90 * SCREENH6, 200 * SCREENH6, 195 * SCREENH6, 197 * SCREENH6)];
    
    contentImageView.image = ImageNamed(@"shoucan");
    
    self.contentImageView = contentImageView;
    
    [self.view addSubview:self.contentImageView];
}


- (void)viewDidLayoutSubviews{
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.mas_equalTo(self.view);
        make.height.mas_equalTo(35 * SCREENH6);
        make.width.mas_equalTo(SCREEN_WIDTH / 2);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.mas_equalTo(self.oneButton);
        make.leading.mas_equalTo(self.oneButton.mas_trailing);
    }];
    
    [self.oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.oneButton.mas_bottom);
        make.height.mas_equalTo(3 * SCREENH6);
//        make.width.mas_equalTo(73 * SCREENH6);
        make.centerX.width.mas_equalTo(self.oneButton);
    }];
    
    [self.twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.mas_equalTo(self.oneLineView);
        make.centerX.mas_equalTo(self.twoButton);
    }];
}

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    
//    return 1;
//}
//
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    
//    
//    return 4;
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    
//    MyCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MycollectionListCell" forIndexPath:indexPath];
//
//    return cell;
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    
//    return 33 * SCREENH6;
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    MyCollectionHeaderView * header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"MyCollectionHeaderView"];
//    
//    return header;
//}

- (UIButton *)setupButtonWith:(NSString *)string{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:string forState:UIControlStateNormal];
    [button setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
    [button setTitleColor:ColorWithRGB(0xF52F4C) forState:UIControlStateSelected];
    button.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}


- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xF52F4C);
    lineView.hidden = YES;
    
    return lineView;
}


- (void)clickButton:(UIButton *)button{
    
    if (button == self.oneButton) {
        
        if (!self.oneButton.selected) {
            
            self.oneLineView.hidden = NO;
            self.oneButton.selected = YES;
            
            self.twoButton.selected = NO;
            self.twoLineView.hidden = YES;
        }
    }else if (button == self.twoButton){
        
        if (!self.twoButton.selected) {
            
            self.twoLineView.hidden = NO;
            self.twoButton.selected = YES;
            
            self.oneButton.selected = NO;
            self.oneLineView.hidden = YES;
        }
    }
}

- (void)backToView {
    
    [self.navigationController popViewControllerAnimated:YES];
}



@end
